USE TIENGUITIETKIEM
GO
ALTER TABLE SOTIETKIEM
ADD CONSTRAINT FK_SOTIETKIEM_KHACH_HANG FOREIGN KEY(MA_KH) REFERENCES KHACH_HANG(MA_KH),
CONSTRAINT FK_SOTIETKIEM_LOAI_TIET_KIEM FOREIGN KEY(MA_LOAITIETKIEM) REFERENCES LOAITIETKIEM(MA_LOAITIETKIEM)
GO
ALTER TABLE LOAITIETKIEM
ADD CONSTRAINT FK_LOAITIETKIEM_LOAITIEN FOREIGN KEY(MA_LOAITIEN) REFERENCES LOAITIEN(MA_LOAITIEN)
GO
ALTER TABLE PHIEU_GUI
ADD CONSTRAINT FK_PHIEU_GUI_SOTIETKIEM FOREIGN KEY(MA_SO) REFERENCES SOTIETKIEM(MA_SO),
CONSTRAINT FK_PHIEU_GUI_LOAITIEN FOREIGN KEY(MA_LOAITIEN) REFERENCES LOAITIEN(MA_LOAITIEN)
GO
ALTER TABLE PHIEU_RUT
ADD CONSTRAINT FK_PHIEU_RUT_KHACH_HANG FOREIGN KEY(MA_KH) REFERENCES KHACH_HANG(MA_KH)
GO
ALTER TABLE CHITIET_PHIEU_RUT
ADD CONSTRAINT FK_CHITIET_PHIEU_RUT_PHIEU_RUT FOREIGN KEY(MA_PHIEU_RUT) REFERENCES PHIEU_RUT(MA_PHIEU_RUT),
CONSTRAINT FK_CHITIET_PHIEU_RUT_SOTIETKIEM FOREIGN KEY(MA_SO) REFERENCES SOTIETKIEM(MA_SO),
CONSTRAINT FK_CHITIET_PHIEU_RUT_LOAITIEN FOREIGN KEY(MA_LOAITIEN) REFERENCES LOAITIEN(MA_LOAITIEN)
GO
ALTER TABLE CHITIET_PHIEU_VAY
ADD CONSTRAINT FK_CHITIET_PHIEU_VAY_LOAITIEN FOREIGN KEY(MA_LOAITIEN) REFERENCES LOAITIEN(MA_LOAITIEN),
CONSTRAINT FK_CHITIET_PHIEU_VAY_TINPHIEU FOREIGN KEY(MA_TINPHIEU) REFERENCES TINPHIEU(MA_TINPHIEU),
CONSTRAINT FK_CHITIET_PHIEU_VAY_PHIEUVAY FOREIGN KEY(MA_PHIEU_VAY) REFERENCES PHIEU_VAY(MA_PHIEU_VAY),
CONSTRAINT FK_CHITIET_PHIEU_VAY_SOTIETKIEM FOREIGN KEY(MA_SO) REFERENCES SOTIETKIEM(MA_SO)
GO
ALTER TABLE PHIEU_VAY
ADD CONSTRAINT FK_PHIEU_VAY_KHACH_HANG FOREIGN KEY(MA_KH) REFERENCES KHACH_HANG(MA_KH)
GO
ALTER TABLE PHIEU_THANHTOAN
ADD CONSTRAINT FK_PHIEU_THANHTOAN_KHACH_HANG FOREIGN KEY(MA_KH) REFERENCES KHACH_HANG(MA_KH),
CONSTRAINT FK_PHIEU_THANHTOAN_LOAITIEN FOREIGN KEY(MA_LOAITIEN) REFERENCES LOAITIEN(MA_LOAITIEN)
GO
ALTER TABLE TINPHIEU
ADD CONSTRAINT FK_TINPHIEU_KHACH_HANG FOREIGN KEY(MA_KH) REFERENCES KHACH_HANG(MA_KH),
CONSTRAINT FK_TINPHIEU_LOAI_TINPHIEU FOREIGN KEY(MA_LOAI_TINPHIEU) REFERENCES LOAI_TINPHIEU(MA_LOAI_TINPHIEU)
GO
ALTER TABLE LOAI_TINPHIEU
ADD CONSTRAINT FK_LOAI_TINPHIEU_LOAITIEN FOREIGN KEY(MA_LOAITIEN) REFERENCES LOAITIEN(MA_LOAITIEN)
GO
ALTER TABLE CHITIET_PHIEU_CHUYEN_NHUONG
ADD CONSTRAINT FK_CHITIET_PHIEU_CHUYEN_NHUONG_TINPHIEU FOREIGN KEY(MA_TINPHIEU) REFERENCES TINPHIEU(MA_TINPHIEU),
CONSTRAINT FK_CHITIET_PHIEU_CHUYEN_NHUONG_PHIEU_CHUYEN_NHUONG FOREIGN KEY(MA_PHIEU_CHUYEN_NHUONG) REFERENCES PHIEU_CHUYEN_NHUONG(MA_PHIEU_CHUYEN_NHUONG)
GO
ALTER TABLE PHIEU_CHUYEN_NHUONG
ADD CONSTRAINT FK_PHIEU_CHUYEN_NHUONG_KHACH_HANG_A FOREIGN KEY(MA_KH_A) REFERENCES KHACH_HANG(MA_KH),
CONSTRAINT FK_PHIEU_CHUYEN_NHUONG_KHACH_HANG_B FOREIGN KEY(MA_KH_B) REFERENCES KHACH_HANG(MA_KH)
GO
ALTER TABLE PHIEU_BAN
ADD CONSTRAINT FK_PHIEU_BAN_KHACH_HANG FOREIGN KEY(MA_KH) REFERENCES KHACH_HANG(MA_KH)
GO
ALTER TABLE CHITIET_PHIEUBAN
ADD CONSTRAINT FK_CHITIET_PHIEUBAN_PHIEU_BAN FOREIGN KEY(MA_PHIEU_BAN) REFERENCES PHIEU_BAN(MA_PHIEU_BAN), 
CONSTRAINT FK_CHITIET_PHIEUBAN_TINPHIEU FOREIGN KEY(MA_TINPHIEU) REFERENCES TINPHIEU(MA_TINPHIEU)